package com.yanqu.road.server.logic.task.condition.kuang;

import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.task.TaskConditionInfo;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.task.BaseCondition;
import com.yanqu.road.server.logic.task.BaseTaskData;

import java.math.BigInteger;
import java.util.List;

public class KuangBattleDay2ScoreCondition extends BaseCondition {


    public KuangBattleDay2ScoreCondition(TaskConditionInfo taskConditionInfo, BaseTaskData baseTaskData, BigInteger value, Object initArgs) {
        super(taskConditionInfo, baseTaskData, value, initArgs);
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.KuangBattleDay2Score.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.KuangBattleDay2Score.getValue(), handle);
    }

    @Override
    public boolean isCompleted(GamePlayer player) {
        List<BigInteger> paramList = taskConditionInfo.getParamList();
        return getValue().compareTo(BigInteger.valueOf(paramList.get(3).intValue())) >= 0;
    }

    @Override
    protected void changeValue(Object object) {
        long value = (long) object;
        if(value > 0) {
            setValue(BigInteger.valueOf(value));
        }
    }
}
